//
// Created by Administrator on 2021/12/14.
//

#include "cdb_connect.hpp"
#include "cdb_pool.hpp"
#include <glog/logging.h>
cdb_connect::cdb_connect()
{

}

cdb_connect::~cdb_connect()
{

}

int cdb_connect::init()
{
    mysql = mysql_init(NULL);
    if(!mysql)
    {
        VLOG(0)<<"mysql_init failed";
        return -1;
    }
    my_bool reconnect = true;
    mysql_options(mysql,MYSQL_OPT_READ_TIMEOUT,&reconnect); // 设置超时
    mysql_options(mysql,MYSQL_SET_CHARSET_NAME,"utf8mb4"); //  设置字符集

    if(!mysql_real_connect(mysql, "127.0.0.1",
                           "chen",
                           "123456",
                           "test",
                           3306, NULL, 0))
    {
        VLOG(0)<<"mysql_real_connect failed";
        return -1;
    }
    VLOG(0)<<"create mysql";
    return 0;
}
std::string cdb_connect::get_pool_name()
{
    return m_pdb_pool->get_pool_name();
}

cdb_connect::cdb_connect(std::shared_ptr<cdb_pool> pool)
{
    this->m_pdb_pool = pool;
}


